﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using SMSSnew.DATA;


namespace SMSSnew.UI
{
    public partial class LeaveHome : System.Web.UI.Page
    {
        public static string userName, fullName, userImageURL;
        LeaveApplicationListDA sendDataToDB;
        LeaveApplicationDA leaveApp;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                userName = Session["username"].ToString();
                fullName = Session["fullName"].ToString();
                userImageURL = Session["userImageURL"].ToString();

                imgUserImage.ImageUrl = userImageURL;
                lblFullName.Text = fullName;

                loadLeavesToGrid();
            }
         }

        protected void loadLeavesToGrid()
        {
            try
            {
                DataTable leaveGrid = new DataTable();
                DataTable earlyLeaveGrid = new DataTable();
                sendDataToDB = new LeaveApplicationListDA();

                leaveGrid = sendDataToDB.loadTeacherLeaves(userName);
                grdRequestedLeaves.DataSource = leaveGrid;
                grdRequestedLeaves.DataBind();

                earlyLeaveGrid = sendDataToDB.loadTeacherEarlyLeaves(userName);
                grdRequestedEarlyLeaves.DataSource = earlyLeaveGrid;
                grdRequestedEarlyLeaves.DataBind();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        protected void imgButFullDay_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("FullDayLeave.aspx");
        }

        protected void imgButHalfDay_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("HalfDayLeave.aspx");
        }

        protected void imgButShortLeave_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("ShortLeave.aspx");
        }

        protected void grdRequestedLeaves_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
             MapDataToControllers(e);
        }

        private void MapDataToControllers(Telerik.Web.UI.GridCommandEventArgs e)
        {
            leaveApp = new LeaveApplicationDA();

            try
            {
                string leaveId = e.Item.Cells[3].Text;

                if (e.CommandName == "deleteLeave")
                {
                    leaveApp.deleteLeave(userName, leaveId);
                    loadLeavesToGrid();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

        protected void imgBtnBack_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("~/UI/Home_Teacher.aspx");

        }

        protected void imgButFullDay_Click(object sender, EventArgs e)
        {
            Response.Redirect("FullDayLeave.aspx");
        }

        protected void imgButHalfDay_Click(object sender, EventArgs e)
        {
            Response.Redirect("HalfDayLeave.aspx?");
        }

        protected void imgButShortLeave_Click(object sender, EventArgs e)
        {
            Response.Redirect("ShortLeave.aspx");
        }

        protected void imgButSpecialMedical_Click(object sender, EventArgs e)
        {
            Response.Redirect("SpecialMedicalLeave.aspx");
        }

        protected void lnkbtnViewEarly_Click(object sender, EventArgs e)
        {
            grdRequestedEarlyLeaves.Visible = true;
            lnkbtnHide.Visible = true;
            lnkbtnViewEarly.Visible = false;
        }

        protected void lnkbtnHide_Click(object sender, EventArgs e)
        {
            grdRequestedEarlyLeaves.Visible = false;
            lnkbtnHide.Visible = false;
            lnkbtnViewEarly.Visible = true;
        }

      

      
        //private void PopUpMessage(String message)
        //{
        //    string alertMsg = "";
        //    alertMsg = "alert('" + message + "');";
        //    if (Page != null && !Page.ClientScript.IsClientScriptBlockRegistered("POPUPMESSAGE"))
        //    {
        //        Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "POPUPMESSAGE", alertMsg, true);
        //    }
        //}
    }
}
